package com.example.hewei.smarttransport.Request;

import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 创意入口的网络请求
 */
public class OriginalyRequest extends TrafficRequest {

    private final static String TAG = "OriginalyRequest";
    private final static String ACTION = "GetAllSense.do";

    private double tempValue;

    /**
     * 构造函数
     *
     * @param userName
     */
    public OriginalyRequest(String userName) {
        super(userName);
    }

    @Override
    protected String getActionName() {
        return ACTION;
    }

    @Override
    protected String onGetJasonBody() {
        JSONObject jsonObj = new JSONObject();
        try {
            // 用户名
            jsonObj.put("username", "aaa");
            // 密码
            jsonObj.put("password", "bbb");
            return jsonObj.toString();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return  super.onGetJasonBody();
    }

    @Override
    protected void onJasonParese(String responseStr) {
        super.onJasonParese(responseStr);
        Log.d(TAG, "onJasonParese: " + responseStr);
        //将String类型转换为Json数据
        try {
            tempValue = new JSONObject(responseStr).getDouble("temp");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public double getTempValue() {
        return tempValue;
    }
}
